'use strict';

const db = uniCloud.database();
const add_db = db.collection('user');
exports.main = async (event, context) => {
	let exit_user = await add_db.where({ 'username': event.username}).count();
	if (exit_user.total == 0){
		await add_db.add({
		  username: event.username,
		  password: event.password,
		  token: event.token,
		  create_time: new Date().getTime(),
		})
		return {
			code: 0,
			msg: '注册成功'
			}
	}else{
		return {
			code: -2,
			msg: '该用户名已被注册，请更换用户名注册'
		}
	}
};
